package com.etc.library.controller;

import com.etc.library.pojo.Carousel;
import com.etc.library.service.CarouselService;
import com.etc.library.util.ResultBody;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/carousel")
public class CarouselController {

    @Autowired
    private CarouselService carouselService;


    @GetMapping("/list")
    public ResultBody list(Integer state) {
        return ResultBody.success(carouselService.list(state));
    }

    @PutMapping("/update")
    public ResultBody update(@RequestBody Carousel carousel) {
        if (carouselService.update(carousel)) {
            return ResultBody.success();
        }
        return ResultBody.error();
    }

    @DeleteMapping("/del/{cid}")
    public ResultBody del(@PathVariable Integer cid) {
        if (carouselService.del(cid))
            return ResultBody.success();
        return ResultBody.error();
    }
}
